package main

import (
	"fmt"
	"gitee.com/menciis/groke"
)

func main() {
	str := `<134>Aug 20 11:59:20 localhost las_mysql_las: 2021-09-13T03:52:27.679565Z 254 [Note] Access denied for user 'root'@'localhost' (using password: NO)`
	//pattern := `^<(\d+)>(\w+\/\d+\/\d+\s*\d+:\d+:\d+)\s*([\s\S]*?)\s*%%\d{2}SHELL\/(\d+)\/LOGOUT\(\w+\)\[\d+\]:([\s\S]*?)（用户类型＝([\s\S]*?)，用户名＝([\s\S]*?)，IP地址＝([\s\S]*?)，VPN名字＝([\s\S]*?)）$`
	g, _ := groke.New()
	//g.AddPattern("Mysql_Date", `(\w{3,4}\s*\d{1,2}\s*\d{1,2}\:\d{1,2}\:\d{1,2})`)
	//g.AddPattern("Mysql_User", `(\w*)`)
	//g.AddPattern("Mysql_Log_Descript", `([\w\W]*)`)
	//g.AddPattern("Mysql", `\<\d{0,3}\>\s*%{Mysql_Date}\s*%{Mysql_User}\s*([\w\-\|]*)\:\s*([\w\-\:\.]*)\s*(\d*)\s*\[(\w*)\]\s*%{Mysql_Log_Descript}`)
	err := g.AddPatternsFromPath("./patterns")
	fmt.Println(err)
	values, _ := g.Parse("%{Mysql}", str)
	for k, v := range values {
		fmt.Println("----", k, v)
	}

	//match := regexp.MustCompile(pattern).FindStringSubmatch(str)
	//for _, s := range match {
	//	fmt.Println("*******", string(s))
	//}
}
